<?php

require_once 'ZendX/JQuery/Form.php';

class Tavs_Form extends ZendX_JQuery_Form
{
    /**
     * Controla se a validacao JQuery esta habilitada ou nao
     *
     * @var bool
     */
    protected $_validateJQuery = false;

    /**
     * Inicializa o formulario
     *
     * @return void
     */
    public function __construct($options = null)
    {
        $this->addPrefixPath('Tavs_Form_Decorator', 'Tavs/Form/Decorator', 'decorator');

        if (isset($options['enableValidateJQuery']) && (bool) $options['enableValidateJQuery'] == true) {
            $this->enableValidateJQuery();
        }

        parent::__construct($options);
    }

    /**
     * Habilita a validacao JQuery
     *
     * @return Tavs_Form
     */
    public function enableValidateJQuery()
    {
        $this->_validateJQuery = true;
        $this->addDecorator('validateJQuery');
        return $this;
    }

    /**
     * Desabilita a validacao
     *
     * @return Tavs_Form
     */
    public function disableValidateJQuery()
    {
        $this->_validateJQuery = false;
        $this->removeDecorator('validateJQuery');
        return $this;
    }

    /**
     * Checa se a validacao JQuery esta habilitada
     *
     * @return bool
     */
    public function isEnabledValidateJQuery()
    {
        return $this->_validateJQuery;
    }
}